/*
 * fileLockHelper.h
 *
 *  Created on: Oct 30, 2011
 *      Author: shaohong
 */

#ifndef FILELOCKHELPER_H_
#define FILELOCKHELPER_H_

#include <fcntl.h>
#include <stdbool.h>

/*
 * Acquire the given type of file lock for the given file
 ARGUMENT
 fd is the file descriptor of the given
 lockType is the type of lock to be acquired. i.e. F_RDLCK, F_WRLCK, F_UNLCK

 RETURN VALUE
 return 0 if successfully acquired the write lock, -1 other wise.
 */
int setFileLock(int fd, short lockType, bool wait);

/**
 * release the file lock on the given fd.
 */
int releaseFileLock(int fd);

#endif /* FILELOCKHELPER_H_ */
